﻿using AnlianCommon.Common.Domains.SheepFarmHouse;
using AnlianCommon.Common.DTO;
using AnlianCommon.Common.Infrastructure.IRepository;
using AnlianCommon.Enum;
using MediatR;
using Microsoft.EntityFrameworkCore;

namespace AnlianCommon.API.Commands.Cottages
{
    public class CottageSecondaryQueryHandler : IRequestHandler<CottageSecondaryQueryCommand, Result>
    {
        private readonly IBaseRepository<Cottage> _cottageRepository;

        public CottageSecondaryQueryHandler(IBaseRepository<Cottage> cottageRepository)
        {
            _cottageRepository = cottageRepository;
        }
        /// <summary>
        /// 查询栋舍用于两级联动
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Result> Handle(CottageSecondaryQueryCommand request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code=(int)CommonErrorCode.Search};
            try
            {
                var cottageList = await (await _cottageRepository.GetAll()).ToListAsync();
                result.Data = cottageList;
            }
            catch (Exception)
            {

                throw;
            }
            return result;
        }
    }
}
